#ifndef _DevicesSoftIIC_H_
#define _DevicesSoftIIC_H_

#define SORT_IIC_ACK    0
#define SORT_IIC_NACK   1
#define SORT_IIC_BUSY   2
#define SORT_IIC_NORMAL 3

#define SORT_IIC_WRITE_MODE 0x00
#define SORT_IIC_READ_MODE  0x01


typedef struct SoftIICStruct{
    GPIO_TypeDef * SclGPIO;
    GPIO_TypeDef * SdaGPIO;

    uint16_t SclPin;
    uint16_t SdaPin;

    void (* GPIOSetMode) (struct SoftIICStruct *pHandle, uint32_t typeMode);

    void (* GPIOSetHigh) (GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
    void (* GPIOSetLow) (GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

    uint8_t (* GPIOReadBit) (GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

    float delayTime;
}SoftIICHandle;



#define SOFT_IIC_OLED_SCK_RCC_GPIO_CLK_ENABLE()             __HAL_RCC_GPIOD_CLK_ENABLE()
#define SOFT_IIC_OLED_SCK_GPIO_Port                         GPIOD
#define SOFT_IIC_OLED_SCK_Pin                               GPIO_PIN_3

#define SOFT_IIC_OLED_SDA_RCC_GPIO_CLK_ENABLE()             __HAL_RCC_GPIOD_CLK_ENABLE()
#define SOFT_IIC_OLED_SDA_GPIO_Port                         GPIOD
#define SOFT_IIC_OLED_SDA_Pin                               GPIO_PIN_4

#define SOFT_IIC_OLED_DELAY_BIT_TIME 1.5f



#define SOFT_IIC_SOC_SCK_RCC_GPIO_CLK_ENABLE()              __HAL_RCC_GPIOB_CLK_ENABLE()
#define SOFT_IIC_SOC_SCK_GPIO_Port                          GPIOB
#define SOFT_IIC_SOC_SCK_Pin                                GPIO_PIN_5

#define SOFT_IIC_SOC_SDA_RCC_GPIO_CLK_ENABLE()              __HAL_RCC_GPIOB_CLK_ENABLE()
#define SOFT_IIC_SOC_SDA_GPIO_Port                          GPIOB
#define SOFT_IIC_SOC_SDA_Pin                                GPIO_PIN_6

#define SOFT_IIC_SOC_DELAY_BIT_TIME 1.5f



#define SOFT_IIC_HIGH_TEMPERATURE_SCK_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define SOFT_IIC_HIGH_TEMPERATURE_SCK_GPIO_Port             GPIOE
#define SOFT_IIC_HIGH_TEMPERATURE_SCK_Pin                   GPIO_PIN_3

#define SOFT_IIC_HIGH_TEMPERATURE_SDA_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define SOFT_IIC_HIGH_TEMPERATURE_SDA_GPIO_Port             GPIOE
#define SOFT_IIC_HIGH_TEMPERATURE_SDA_Pin                   GPIO_PIN_4

#define SOFT_IIC_HIGH_TEMPERATURE_DELAY_BIT_TIME 4





extern SoftIICHandle ex_SoftIICOledHandle;
extern SoftIICHandle ex_SoftIICSOCHandle;
extern SoftIICHandle ex_SoftIICHighTemperatureHandle;




void vSoftIICxSetSdaGPIOMode(SoftIICHandle *pHandle, uint32_t typeMode);
int8_t cSoftIICxWriteDatas(SoftIICHandle *pHandle, uint8_t ucAddr, uint8_t ucReg, uint8_t *pucDatas, uint32_t iLength);
int8_t cSoftIICxReadDatas(SoftIICHandle *pHandle, uint8_t ucAddr, uint8_t ucReg, uint8_t *pucDatas, int32_t iLength);



void vSoftIICOledInit(void);
#define cSoftIICOledWriteDatas(ucAddr, ucReg, pucDatas, iLength) cSoftIICxWriteDatas(&ex_SoftIICOledHandle, ucAddr, ucReg, pucDatas, iLength)
#define cSoftIICOledReadDatas(ucAddr, ucReg, pucDatas, iLength) cSoftIICxReadDatas(&ex_SoftIICOledHandle, ucAddr, ucReg, pucDatas, iLength)


void vSoftIICSOCInit(void);
#define cSoftIICSOCWriteDatas(ucAddr, ucReg, pucDatas, iLength) cSoftIICxWriteDatas(&ex_SoftIICSOCHandle, ucAddr, ucReg, pucDatas, iLength)
#define cSoftIICSOCReadDatas(ucAddr, ucReg, pucDatas, iLength) cSoftIICxReadDatas(&ex_SoftIICSOCHandle, ucAddr, ucReg, pucDatas, iLength)


void vSoftIICHighTemperatureInit(void);
#define cSoftIICHighTemperatureWriteDatas(ucAddr, ucReg, pucDatas, iLength) cSoftIICxWriteDatas(&ex_SoftIICHighTemperatureHandle, ucAddr, ucReg, pucDatas, iLength)
#define cSoftIICHighTemperatureReadDatas(ucAddr, ucReg, pucDatas, iLength) cSoftIICxReadDatas(&ex_SoftIICHighTemperatureHandle, ucAddr, ucReg, pucDatas, iLength)



#endif
